package org.bambrikii.kbManager.kb2.managers;

import org.bambrikii.kbManager.kb2.dao.IArtefactAsImageDAO;
import org.bambrikii.kbManager.kb2.dao.IArtefactAsTextDAO;
import org.bambrikii.kbManager.kb2.dao.IArtefactDAO;
import org.bambrikii.kbManager.kb2.managers.query5.ICriteria;
import org.bambrikii.kbManager.kb2.model.Artefact;
import org.bambrikii.kbManager.kb2.model.ArtefactAsImage;
import org.bambrikii.kbManager.kb2.model.ArtefactAsText;
import org.bambrikii.site.base.business.managers.ManagerBase;
import org.bambrikii.site.base.business.managers.core.ManagerException;
import org.bambrikii.site.base.model.Pager;

public class ArtefactManager extends ManagerBase<Artefact, IArtefactDAO> {

	private final IArtefactAsTextDAO txtDao;
	private final IArtefactAsImageDAO imgDao;

	public ArtefactManager(IArtefactDAO dao, IArtefactAsTextDAO txtDao,
			IArtefactAsImageDAO imgDao) throws ManagerException {
		super(dao);
		this.txtDao = txtDao;
		this.imgDao = imgDao;
	}

	public void saveText(final ArtefactAsText txt) {
		txtDao.saveOrUpdate(txt);
	}

	public void deleteText(final ArtefactAsText txt) {
		txtDao.delete(txt);
	}

	public void saveImage(final ArtefactAsImage img) {
		imgDao.saveOrUpdate(img);
	}

	public void deleteImage(final ArtefactAsImage img) {
		imgDao.delete(img);
	}

	public Pager<ArtefactAsText> getArtefacts(final String title,
			final Integer currPage, final Integer txtPagerCols,
			final Integer txtPagerRows) {
		final ArtefactAsTextPagerBuilder b = new ArtefactAsTextPagerBuilder(
				txtDao);
		b.restrict(title);
		return b.getPager(txtPagerCols, txtPagerRows, "title", currPage);
	}

	public Pager<ArtefactAsText> getLanguages(final String title,
			final Integer currPage, final Integer txtPagerCols,
			final Integer txtPagerRows) {
		final ArtefactAsTextPagerBuilder b = new ArtefactAsTextPagerBuilder(
				txtDao);
		b.restrict(title, "Language");
		return b.getPager(txtPagerCols, txtPagerRows, "title", currPage);
	}

	public Pager<ArtefactAsText> getArtefacts(final ICriteria filter,
			final Integer currPage, final Integer cols, final Integer rows) {
		final ArtefactAsTextPagerBuilder b = new ArtefactAsTextPagerBuilder(
				txtDao);
		return b.getPager(filter, currPage, cols, rows);
	}
}
